<template>
  <div class="container" ref="mainCon">
    <!-- <el-row>
            <el-col class="topTitle">
                <el-row>
                    <i class="icon iconfont iconfanhui1" @click="goBack"></i>
                    <span class="title">参评项目列表</span>
                </el-row>
            </el-col>
        </el-row> -->
    <topTitle
      :titleText="`参评项目列表`"
      :back="true"
      @gobackTriser="goBack"
    ></topTitle>
    <!-- <div class="spacing"></div> -->
    <div class="info">
      <el-row>
        <el-col :span="18" style="height: 84px">
          <el-row>
            <p
              style="
                font-size: 24px;
                color: #3a3a3a;
                margin-top: 12px;
                text-align: left;
                font-weight: bold;
              "
            >
              {{ enterpriseInfo.companyName }}
            </p>
          </el-row>
          <el-row style="margin-top: 8px">
            <el-col :span="7" style="min-width: 300px">
              <span class="dot"
                >统一社会信用代码：{{ enterpriseInfo.uscc || '--' }}</span
              >
            </el-col>
            <!-- <el-col :span="5">
                            <span class="dot">企业联系人：{{enterpriseInfo.enterpriseMan}}</span>
                        </el-col>-->
            <!-- <el-col :span="6">
                            <span class="dot">联系方式：{{enterpriseInfo.enterpriseTel}}</span>
                        </el-col>-->
          </el-row>
        </el-col>
        <el-col
          class="dynamic"
          :span="3"
          style="height: 84px; border-left: 1px solid #e4ebf1"
          v-if="!isHsUser()"
        >
          <p>
            <span class="score fontColorTheme">{{
              enterpriseInfo.score == null ? '--' : enterpriseInfo.score
            }}</span>
            <span
              class="fontColorTheme"
              style="font-size: 14px; color: #009588; text-align: center"
              >分</span
            >
          </p>
          <p>动态信用分数</p>
        </el-col>
        <el-col
          class="dynamic fontColorTheme"
          :span="3"
          style="height: 84px; border-left: 1px solid #e4ebf1"
          v-if="!isHsUser()"
        >
          <p class="score fontColorTheme">
            {{ enterpriseInfo.gradeLevel || '--' }}
          </p>
          <p>动态信用等级</p>
        </el-col>
        <el-col
          class="dynamic fontColorTheme"
          :span="3"
          style="height: 84px; border-left: 1px solid #e4ebf1"
          v-if="isHsUser()"
        >
          <p>
            <span class="score fontColorTheme">{{
              enterpriseInfo.companyAvgScore == null
                ? '--'
                : enterpriseInfo.companyAvgScore
            }}</span>

            <span
              class="fontColorTheme"
              style="font-size: 14px; color: #009588; text-align: center"
              >分</span
            >
            <span class="score fontColorTheme"
              >/{{ enterpriseInfo.companyAvgGradeLevel || '--' }}</span
            >
          </p>
          <p>月度平均信用分数/等级</p>
        </el-col>
        <el-col
          class="dynamic"
          :span="3"
          style="height: 84px; border-left: 1px solid #e4ebf1"
          v-if="isHsUser()"
        >
          <p>
            <span class="score fontColorTheme">{{
              enterpriseInfo.score == null ? '--' : enterpriseInfo.score
            }}</span>

            <span
              class="fontColorTheme"
              style="font-size: 14px; color: #009588; text-align: center"
              >分</span
            >
            <span class="score fontColorTheme"
              >/{{ enterpriseInfo.gradeLevel || '--' }}</span
            >
          </p>
          <p>今日信用分数/等级</p>
        </el-col>
      </el-row>
    </div>
    <div class="spacing"></div>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <!-- <label>
                        项目名称&ensp;
                        <input
                            type="text"
                            placeholder="请输入项目名称"
                            v-model="filterField.projectName"
                            clearable
                        />
                    </label> -->
          <el-col :lg="8" :xl="6">
            <el-form-item label="项目名称" class="row-padding-bottom name">
              <el-input
                placeholder="请输入项目名称"
                clearable
                v-model="filterField.projectName"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="8" :xl="6">
            <el-form-item label="项目状态" class="row-padding-bottom">
              <el-select
                v-model="filterField.projectStatus"
                filterable
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="(item, index) in projectState"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :lg="8" :xl="6">
              <el-form-item label="项目信用等级" class="row-padding-bottom">
                <el-select
                  v-model="filterField.projectGradeLevel"
                  filterable
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="(item, index) in selectLevel"
                    :key="index"
                    :label="item.name"
                    :value="item.gradeLevel"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
          <el-col :lg="8" :xl="6">
            <el-form-item label="">
              <a
                @click="toggleAdvanced"
                style="margin-left: 40px; color: #409eff; cursor: pointer"
                class="btnColor"
              >
                {{ advanced ? '收起' : '展开' }}
                <i
                  :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i>
              </a>
              <el-button
                type="primary"
                icon="icon iconfont iconchazhao1"
                @click="searchList"
                class="searchBtn"
              >
                <span>搜索</span>
              </el-button>
            </el-form-item>
          </el-col>
          <!-- <el-form-item>
                        <el-button
                            type="primary"
                            icon="icon iconfont iconchazhao1"
                            @click="searchList"
                            class="commonBtn"
                        ></el-button>
                    </el-form-item> -->
        </el-form>
      </el-row>
      <div
        ref="tableBox"
        :class="hiddleToolBar ? 'tableBoxCur tableBox' : 'tableBoxCur'"
        style="padding-top: 0"
      >
        <el-table
          ref="tableBox1"
          :max-height="tableHeight"
          :data="tableList"
          v-loading="loading"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
          highlight-current-row
          stripe
          style="border: 1px solid #dfe6ec"
          @sort-change="sortChange"
        >
          <el-table-column
            label="序号"
            type="index"
            width="80"
          ></el-table-column>
          <!-- <el-table-column
                    prop="companyName"
                    label="单位名称"
                    align="left"
                ></el-table-column>
                <el-table-column
                    prop="typeDesc"
                    label="单位角色"
                    align="center"
                    :formatter="formatTd"
                ></el-table-column>
                <el-table-column
                    prop="uscc"
                    label="统一社会信用代码"
                    align="center"
                    :formatter="formatTd"
                ></el-table-column> -->
          <!-- <el-table-column
                    prop="projectName"
                    label="项目名称"
                    align="center"
                    :formatter="formatTd"
                ></el-table-column> -->
          <el-table-column label="项目名称" width="230">
            <template slot-scope="scope">
              <copyText
                :tableIndex="scope.$index"
                :copyTextName="scope.row.projectName"
                :columnName="'projectName'"
              ></copyText>
            </template>
          </el-table-column>
          <el-table-column
            prop="projectStatusDesc"
            label="项目状态"
            align="center"
            :formatter="formatTd"
          ></el-table-column>
          <!-- 黄石需求 - start -->
          <el-table-column
            prop="projectScore"
            label="月度平均信用分数/等级"
            align="center"
            :formatter="formatTd"
            v-if="isHsUser()"
            key="1"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="scope.row.avgScore || scope.row.avgGradeLevel"
                @click="toProjectDetail(scope.row, 'month')"
                >{{ scope.row.avgScore || '--' }}/{{
                  scope.row.avgGradeLevel || '--'
                }}</el-link
              >
              <el-link
                v-else
                @click="toProjectDetail(scope.row, 'month')"
                type="primary"
                >尚未生成</el-link
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="projectScore"
            label="今日信用分数/等级"
            align="center"
            :formatter="formatTd"
            v-if="isHsUser()"
            key="2"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                v-if="scope.row.projectScore || scope.row.projectGradeLevel"
                @click="toProjectDetail(scope.row, 'today')"
                >{{ scope.row.projectScore }}/{{
                  scope.row.projectGradeLevel
                }}</el-link
              >
              <el-link
                v-else
                @click="toProjectDetail(scope.row, 'today')"
                type="primary"
                >尚未生成</el-link
              >
            </template>
          </el-table-column>
          <!-- 黄石需求 - end -->
          <el-table-column
            prop="projectScore"
            label="项目信用分数"
            align="center"
            :formatter="formatTd"
            v-if="!isHsUser()"
            key="3"
            sortable="custom"
          ></el-table-column>
          <el-table-column
            label="项目信用等级"
            align="center"
            :formatter="formatTd"
            v-if="!isHsUser()"
            key="4"
          >
            <template slot-scope="scope">
              {{
                scope.row.projectGradeLevel === 'O'
                  ? '其他'
                  : scope.row.projectGradeLevel
              }}
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="left"
            :formatter="formatTd"
            v-if="!isHsUser()"
            key="5"
          >
            <template slot-scope="scope">
              <el-link type="primary" @click="toDetail(scope.row)"
                >查看详情</el-link
              >
            </template>
          </el-table-column>
          <!-- 表格数据为空时，页面显示 -->
          <div slot="empty" v-show="isShow">
            <emptyTable emptyText="暂无企业评级相关数据"></emptyTable>
          </div>
        </el-table>

        <!-- getTableList为获取子组件的数据 -->
        <Pagination
          ref="pagination"
          @getList="getTableList"
          :filterField="filterField"
          :requestUrl="requestUrl"
        ></Pagination>
      </div>
    </div>
  </div>
</template>

<script>
import emptyTable from '@/components/publicCom/emptyTable'
import Pagination from '@/components/publicCom/pagination'
import scrollTable from '@/mixin/scrollTable.js'
export default {
  name: 'scoreProjectList',
  mixins: [scrollTable],
  components: {
    emptyTable,
    Pagination,
  },
  data() {
    return {
      projectState: [],
      advanced: false,
      selectLevel: [],
      //表格数据
      tableList: [],
      requestUrl: 'api-ps/creditComProjScore/expand/getCompanyProjectScoreList',
      //搜索条件
      filterField: {
        type: '',
        uscc: '',
        projectName: '',
        projectStatus: '',
        projectGradeLevel: '',
      },
      isShow: false, //列表加载
      loading: false,
      enterpriseInfo: {},
      page: '',
    }
  },
  // beforeRouteEnter(to, from, next) {
  // console.log(to);
  // if (from.name === "scoreList") {
  //     next((vm) => {
  //         vm.isIndex = from.query.index;
  //         vm.scoreDimType = vm.scoreDimTypeEnum[vm.isIndex * 1];
  //     });
  // } else {
  //     next();
  // }
  // next((vm) => {
  //     vm.filterField.type = to.query.scoreDimType;
  //     vm.filterField.uscc = to.query.uscc;
  //     console.log(222, vm.filterField.type, vm.filterField.uscc);
  // });
  // },
  async created() {
    this.filterField.type = this.$route.query.type
    this.filterField.uscc = this.$route.query.uscc
    if (this.$route.query.page) {
      this.page = this.$route.query.page
    }

    this.getProjectState()
    this.getLevelList(this.filterField.type)
    this.getEnterpriseInfo(this.filterField.type, this.filterField.uscc)
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
  },
  methods: {
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    // 评分详情
    getEnterpriseInfo(type, uscc) {
      this.axios({
        method: 'post',
        url: 'api-ps/creditComProjScore/expand/getCompanyScore',
        data: {
          type,
          uscc,
        },
      })
        .then((response) => {
          if (response.data.hasError) {
            this.$message.error(response.data.errorMsg)
          } else {
            this.enterpriseInfo = response.data.result
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    // 获取评级配置
    getLevelList(type) {
      return this.axios({
        method: 'post',
        url: 'api-ps/creditLevel/expand/getCreditLevelList',
        data: {
          type,
        },
      })
        .then((response) => {
          if (response.data.hasError) {
            this.$message.error(response.data.errorMsg)
          } else {
            const results = response.data.result
            results.forEach((v) => {
              v.name = v.gradeLevel
            })
            this.selectLevel = results
            const otherLevel = { gradeLevel: 'O', name: '其他' }
            this.selectLevel.push(otherLevel)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    // 项目状态
    getProjectState() {
      return this.axios({
        method: 'post',
        url: 'api-p/projectstats/expand/status',
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.projectState = response.data.result.filter(
              (v) => v.id != 'NOT_STARTED'
            )
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    toDetail(row) {
      if (this.page == 'dataSharingSettings') {
        let path = '/home/enterpriseScore/scoreDetail'
        let name = 'scoreDetail'
        if (this.isEsUser()) {
          path = '/home/enterpriseScore/ESscoreDetail'
          name = 'ESscoreDetail'
        }
        this.$router.push({
          path,
          name,
          query: {
            companyProjectScoreId: row.id,
            type: row.type,
            projectId: row.projectId,
            uscc: row.uscc,
            page: 'dataSharingSettings',
          },
        })
        this.$store.commit('CHANGE_SLIDER_NAME', {
          oldUrl: '/home/networkGrid/dataSharingSettings',
          newUrl: this.$router.currentRoute.fullPath,
        })
      } else {
        let path = '/home/enterpriseScore/scoreDetail'
        let name = 'scoreDetail'
        if (this.isEsUser()) {
          path = '/home/enterpriseScore/ESscoreDetail'
          name = 'ESscoreDetail'
        }
        this.$router.push({
          path,
          name,
          query: {
            companyProjectScoreId: row.id,
            type: row.type,
            projectId: row.projectId,
            uscc: row.uscc,
          },
        })
        this.$store.commit('CHANGE_SLIDER_NAME', {
          oldUrl: '/home/enterpriseScore/scoreList',
          newUrl: this.$router.currentRoute.fullPath,
        })
      }
    },
    goBack() {
      if (this.page == 'dataSharingSettings') {
        this.$router.push({
          path: '/home/networkGrid/dataSharingSettings',
          name: 'dataSharingSettings',
          query: {
            tab: 'qyEvaluation',
          },
        })
        this.$store.commit('GOBACK_NAME', {
          oldUrl: '/home/networkGrid/dataSharingSettings',
          newUrl: this.$router.currentRoute.fullPath,
        })
      } else {
        this.$router.push({
          path: '/home/enterpriseScore/scoreList',
          name: 'scoreList',
        })
        this.$store.commit('GOBACK_NAME', {
          oldUrl: '/home/enterpriseScore/scoreList',
          newUrl: this.$router.currentRoute.fullPath,
        })
      }
    },
    // 黄石定制需求-跳转详情
    toProjectDetail(row, activeTab) {
      this.$router.push({
        path: '/home/enterpriseScore/HSscoreDetail',
        name: 'HSscoreDetail',
        query: {
          companyProjectScoreId: row.id,
          type: row.type,
          projectId: row.projectId,
          uscc: row.uscc,
          activeTab: activeTab,
          companyAvgScore: row.avgScore,
        },
      })
      this.$store.commit('GOBACK_NAME', {
        oldUrl: '/home/enterpriseScore/scoreList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style scoped lang="less">
@import '../../../static/css/filterArea.less';
.container {
  // padding: 24px;
  .topTitle {
    height: 66px;
    background-color: #e4ebf1;
    padding-left: 24px;
    .title {
      font-family: 'SourceHanSansCN-Medium';
      font-size: 18px;
      color: #333333;
      line-height: 66px;
      font-weight: bold;
    }
    .text {
      font-family: 'SourceHanSansCN-Regular';
      font-size: 14px;
      color: #666666;
      text-indent: 32px;
      margin-top: 8px;
    }
  }
  .info {
    height: 106px;
    background: #ffffff;
    padding-left: 24px;
    padding-top: 12px;
    padding-bottom: 12px;
    .dot {
      font-size: 14px;
      color: #666666;
      position: relative;
      // padding-left: 12px;
      // &::before {
      //     content: "";
      //     background: #009588;
      //     border-radius: 50%;
      //     width: 6px;
      //     height: 6px;
      //     position: absolute;
      //     top: 4px;
      //     left: 0;
      // }
    }
    .dynamic {
      padding-top: 15px;
    }
    p {
      font-size: 12px;
      color: #999999;
      text-align: center;
    }
    .score {
      font-size: 28px;
      color: #009588;
      text-align: center;
      font-weight: bold;
    }
  }
  .mainCon {
    top: 322px;
    padding-top: 24px;
  }
}
input {
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 36px;
  line-height: 36px;
  outline: 0;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 264px;
}
input::-webkit-input-placeholder {
  /* WebKit browsers */
  font-family: 'SourceHanSansCN-Regular';
  font-size: 14px;
  color: #cccccc;
}
input:-moz-placeholder {
  /* Mozilla Firefox 4 to 18 */
  font-family: 'SourceHanSansCN-Regular';
  font-size: 14px;
  color: #cccccc;
}
input::-moz-placeholder {
  /* Mozilla Firefox 19+ */
  font-family: 'SourceHanSansCN-Regular';
  font-size: 14px;
  color: #cccccc;
}
input:-ms-input-placeholder {
  /* Internet Explorer 10+ */
  font-family: 'SourceHanSansCN-Regular';
  font-size: 14px;
  color: #cccccc;
}
label {
  font-family: 'SourceHanSansCN-Normal';
  font-size: 14px;
  color: #333333;
  text-align: right;
  margin-right: -12px;
}
/deep/ .el-form-item__label {
  font-family: 'SourceHanSansCN-Normal';
  font-size: 14px;
  color: #333333;
  text-align: right;
}
</style>
